<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>物流管理系统</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <%--    <!--<base th:href="${#request.getContextPath()}">-->--%>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body class="login-bg">

<div class="login layui-anim layui-anim-up">
    <div class="message">物流管理系统</div>
    <div id="darkbannerwrap"></div>
    <form method="post" class="layui-form">
        <input name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <div class="layui-form-item">
            <div class="layui-inline">
                <input type="text" name="verity" required lay-verify="required" placeholder="验证码" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-inline">
                <img class="verifyImg" id="verifyImg" onclick="javascript:getvCode();"/>
            </div>
        </div>
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
        <hr class="hr20">
    </form>
    <div><!--class="bottom-link" -->
        还没有帐号?<a href="register.jsp" class="_j_go_register">马上注册</a>
    </div>
</div>


<script>
    /**
     * 获取验证码
     * 将验证码写到login.html页面的id = verifyimg 的地方
     */
    function getvCode() {

        $("#verifyImg").attr('src', timestamp("captcha"));
    }

    //为url添加时间戳
    function timestamp(url) {
        const getTimestamp = new Date().getTime();
        if (url.indexOf("?") > -1) {
            url = url + "&timestamp=" + getTimestamp
        } else {
            url = url + "?timestamp=" + getTimestamp
        }
        console.log(url)
        return url;
    }

    $(function () {
        getvCode();
        layui.use('form', function () {
            var form = layui.form;
            //监听提交
            form.on('submit(login)', function (data) {
                console.log(data)
                $.post("login.do", data.field, function (res) {
                    if (res.code == 200) {
                        layer.msg("登录成功，正在跳转...", {time: 800}, function () {
                            top.location.href = 'user/list';
                        });
                    } else {
                        layer.msg(res.msg)
                        getvCode()
                    }
                }, "json");
                return false;
            });
        });
    })

</script>

</body>
</html>
